package com.poetize.plus.entity.vo;

import com.fasterxml.jackson.annotation.JsonFormat;
import com.poetize.plus.entity.po.User;
import io.swagger.v3.oas.annotations.media.Schema;

import java.time.LocalDateTime;
import java.util.ArrayList;
import java.util.List;

/**
 * @author zuosy
 * @created 2024/3/29 10:00
 */
public record UserPageVO(
        @Schema(description = "ID")
        Long id,

        @Schema(description = "用户名")
        String username,

        @Schema(description = "角色")
        String role,

        @Schema(description = "邮箱")
        String email,

        @Schema(description = "性别")
        String gender,

        @Schema(description = "头像")
        String avatar,

        @Schema(description = "简介")
        String introduction,

        @Schema(description = "是否禁用")
        Boolean forbidden,

        @Schema(description = "创建时间")
        @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss")
        LocalDateTime createTime
) {

    /**
     * 数据集合转分页集合
     *
     * @param userList
     * @return
     */
    public static List<UserPageVO> convertPageList(List<User> userList) {
        List<UserPageVO> result = new ArrayList<>();
        userList.forEach(user -> {
            UserPageVO vo = new UserPageVO(
                    user.getId(),
                    user.getUsername(),
                    user.getRole(),
                    user.getEmail(),
                    user.getGender(),
                    user.getAvatar(),
                    user.getIntroduction(),
                    user.getForbidden(),
                    user.getCreateTime());
            result.add(vo);
        });
        return result;
    }
}
